package uk.org.aspellclark.gedcom.controller;

import java.util.ArrayList;
import java.util.List;

import uk.org.aspellclark.gedcom.model.records.FamRecord;
import uk.org.aspellclark.gedcom.model.records.IndividualRecord;

import com.db4o.ObjectSet;
import com.db4o.foundation.NotImplementedException;

public class FamilyController extends AbstractDB4OController {

	public FamilyController(Db4oController dbCntrl) {
		super(dbCntrl);
	}

	/**
	 * @param f
	 */
	public void addFamily(FamRecord f) {
		this.dbCntrlr.db.store(f);
	}

	/**
	 * @param indiv
	 * @return
	 */
	public List<IndividualRecord> getChildren(IndividualRecord indiv) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * get the children of a family.
	 * @param familyId
	 * @return
	 */
	public ArrayList<IndividualRecord> getChildren(String familyId) {
		throw new NotImplementedException();
	}

	/**
	 * @return
	 */
	public List<FamRecord> getFamilies() {
		List<FamRecord> objList = this.dbCntrlr.db.queryByExample(FamRecord.class);
		return objList;
	}

	/**
	 * @param xref
	 * @return
	 */
	public FamRecord getFamily(String xref) {
		FamRecord ind = new FamRecord(xref);
		ObjectSet<FamRecord> retrndObjs = this.dbCntrlr.db.queryByExample(ind);

		if (retrndObjs.size() == 1) {
			ind = retrndObjs.next();
		} else {
			ind = null;
		}
		return ind;
	}

	/**
	 * get the family that a person is a spouse in.
	 * @param individualId
	 * @return
	 */
	public FamRecord getFamilyFromSpouse(String individualId) {
		IndividualController individualCntrlr = new IndividualController(this.dbCntrlr);
		IndividualRecord ind = individualCntrlr.getIndividual(individualId);

		throw new NotImplementedException();
	}

}
